package mms

import com.lucastex.grails.fileuploader.UFile
// 多媒体内容企业的，图片，视频，flash，语音等信息
class Multimedia {

    String description 
    String path
    String url
    String mediaType // pic , video, flash , voice
    String preview = ""


//    static hasMany = []
//    static belongsTo = []
//    static transients = []


//    table 'xedu_article'
//    sort  lastTime
    static mapping = {
    }
    //blank 
    //email
    //inList
    //matches 
    //nullable 
    //size
    //unique
    //url 
    static constraints = {
        description(size:0..2000)
        path(blank:true ,size:0..200)
        url(size:0..200)
        mediaType(inList:['picture','video','flash','voice'])// pic , video, flash , voice
        preview(blank:true ,size:0..200)
    }

    String toString() { 
        description
    } 

    def afterDelete = {
		try {
            UFile.withNewSession {
                UFile f = UFile.get(description.toLong())
                f.delete(flush:true)
                log.info "UFile [${path}] deleted"
            }
		} catch (Exception exp) {
			log.info "Error deleting file: ${exp.message}"
			log.info exp
		}
	}
}
